﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.UC.下单MTO.Service;
using DXApplicationTangche.UC.订单一览新.客户充值;
using DXApplicationTangche.UC.订单一览新.销售确认单;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.下单MTO
{
    public partial class FormMTO客户一览 : DevExpress.XtraEditors.XtraForm
    {
        private List<CustomerPDTO> customerPDTOs = new List<CustomerPDTO>();
        public CustomerPDTO customerchoosePDTO;
        public FormMTO客户一览(CustomerPDTO customerchoosePDTO)
        {
            InitializeComponent();
            this.customerchoosePDTO = customerchoosePDTO;
            this.selectCustomers();
        }

        private void selectCustomers()
        {
            //this.customerPDTOs = MTO订单Service.findAllCustomers();
            this.customerPDTOs = MTO订单Service.findAllCustomersWIthMembershipType();
            this.gridControl客户一览.DataSource = this.customerPDTOs;
            this.gridView客户一览.RefreshData();
            //this.gridView客户一览.BestFitColumns();
        }

        private void gridView客户一览_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            this.customerchoosePDTO.build(
                FunctionHelper.GetgridViewValue(this.gridView客户一览, e.RowHandle, "mobile"),
                FunctionHelper.GetgridViewValue(this.gridView客户一览, e.RowHandle, "customerName"),
                FunctionHelper.GetgridViewValue(this.gridView客户一览, e.RowHandle, "addressProvince"),
                FunctionHelper.GetgridViewValue(this.gridView客户一览, e.RowHandle, "addressCity"),
                FunctionHelper.GetgridViewValue(this.gridView客户一览, e.RowHandle, "addressDistrict"),
                FunctionHelper.GetgridViewValue(this.gridView客户一览, e.RowHandle, "addressDetail")
                );
            
            this.Close();
        }

        private void 更改会员类型ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String mobile = FunctionHelper.GetgridViewValue(this.gridView客户一览, this.gridView客户一览.FocusedRowHandle, "mobile");
            String membershipType = FunctionHelper.GetgridViewValue(this.gridView客户一览, this.gridView客户一览.FocusedRowHandle, "membershipType");
            if ("充值会员".Equals(membershipType))
            {
                return;
            }
            new Form会员类型维护(mobile).ShowDialog();
            this.selectCustomers();
        }
    }
}
